<template>
  <div class="user-search">
    <el-form :model="searchForm" ref="formRef" label-width="80px" size="large">
      <!-- 第一行 -->
      <el-row :gutter="20">
        <el-col :span="8">
          <el-form-item label="用户名" prop="name">
            <el-input
              v-model="searchForm.name"
              placeholder="请输入用户名"
            ></el-input> </el-form-item
        ></el-col>
        <el-col :span="8">
          <el-form-item label="真实姓名" prop="realname">
            <el-input
              placeholder="请输入真实姓名"
              v-model="searchForm.realname"
            ></el-input> </el-form-item
        ></el-col>
        <el-col :span="8">
          <el-form-item label="电话号码" prop="cellphone">
            <el-input
              placeholder="请输入电话号码"
              v-model="searchForm.cellphone"
            ></el-input>
          </el-form-item>
        </el-col>

        <!-- 第二行 -->
        <el-col :span="8">
          <el-form-item label="状态" prop="enable">
            <!-- <el-input placeholder="请输入状态"></el-input> -->
            <el-select placeholder="请输入状态" v-model="searchForm.enable">
              <el-option label="启用" :value="1" />
              <el-option label="禁用" :value="0" />
            </el-select> </el-form-item
        ></el-col>

        <el-col :span="8">
          <el-form-item label="创建时间" prop="createAt">
            <!-- <el-input placeholder="请输入创建时间"></el-input>  -->
            <el-date-picker
              type="daterange"
              placeholder="请输入创建时间"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              v-model="searchForm.createAt"
            /> </el-form-item
        ></el-col>
      </el-row>
    </el-form>

    <div class="btns">
      <el-button
        type="default"
        size="large"
        icon="Refresh"
        @click="handleResetClick"
        >重置</el-button
      >
      <el-button
        type="primary"
        size="large"
        icon="Search"
        @click="handleQueryClick"
        >搜索</el-button
      >
    </div>
  </div>
</template>

<script setup lang="ts">
import type { ElForm } from 'element-plus'
import { reactive, ref } from 'vue'

// 定义自定义事件
const emit = defineEmits(['queryClick', 'resetClick'])

// 定义表单数据
const searchForm = reactive({
  name: '',
  realname: '',
  cellphone: '',
  enable: 1,
  createAt: ref()
})

// 重置表单
const formRef = ref<InstanceType<typeof ElForm>>()
function handleResetClick() {
  // 清空表单
  formRef.value?.resetFields()

  emit('resetClick')
}

function handleQueryClick() {
  emit('queryClick', searchForm)
}
</script>

<style lang="less" scoped>
.user-search {
  padding: 20px;

  background-color: #fff;
  .el-form-item {
    padding: 20px 30px;
    margin-bottom: 0;
  }
  .btns {
    padding-right: 50px;
    text-align: right;
    .el-button {
      height: 36px;
    }
  }
}
</style>
